package org.example.cicdi.service.impl.ext;


import org.example.codegenerate.modelext.WebVo.domian.column.ColumnVoDomain;
import org.example.codegenerate.modelext.WebVo.domian.table.WebModelVo;

import java.lang.reflect.Field;
import java.util.Optional;

public abstract class AbstactFieldAnnotationServiceExt implements FieldAnnotationServiceExt {

    @Override
    public String getCode() {
        return null;
    }

    @Override
    public void handleFieldVo(Field field, WebModelVo model) {
        Optional<ColumnVoDomain> optionalColumnVoDomian= model.getTableVoDomain().getColumnVoDomainList()
                .stream()
                .filter(x->x.getDbVo().getDbFieldName().equals(field.getName()))
                .findFirst()
                ;
        ColumnVoDomain columnVoDomain;
        if(optionalColumnVoDomian.isPresent()){
            columnVoDomain =optionalColumnVoDomian.get();
        }else {
            columnVoDomain =new ColumnVoDomain();
            model.getTableVoDomain().getColumnVoDomainList().add(columnVoDomain);
        }
        execute(columnVoDomain,field,model);
    }

    protected abstract  void execute(ColumnVoDomain columnVoDomain, Field field, WebModelVo model) ;
}
